home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / FishHack / source / CBasicApp.cp < prev    next >
Text File  |  2000-06-23  |  5KB  |  188 lines

  1. // ===========================================================================
  2. //    CBasicApp.cp                 ©1994-1998 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //    This file contains the starter code for a basic PowerPlant project
  5.  
  6. #include "CBasicApp.h"
  7.  
  8. #include <LGrowZone.h>
  9. #include <PP_Messages.h>
  10. #include <PP_Resources.h>
  11. #include <PPobClasses.h>
  12. #include <UDrawingState.h>
  13. #include <UMemoryMgr.h>
  14. #include <URegistrar.h>
  15.  
  16. #include <LWindow.h>
  17. #include <LCaption.h>
  18. #include <LStdControl.h>
  19.  
  20. // put declarations for resource ids (ResIDTs) here
  21.  
  22.  
  23. const PP_PowerPlant::ResIDT    wind_SampleWindow             = 128;    // EXAMPLE, create a new window
  24. const PP_PowerPlant::MessageT    MSG_Fish                = 'Fish';
  25. const PP_PowerPlant::PaneIDT    Button_Fish                = 2048;
  26.  
  27.  
  28. // ===========================================================================
  29. //        • Main Program
  30. // ===========================================================================
  31.  
  32. int main()
  33. {
  34.                                 
  35.     SetDebugThrow_(PP_PowerPlant::debugAction_Alert);    // Set Debugging options
  36.     SetDebugSignal_(PP_PowerPlant::debugAction_Alert);
  37.  
  38.     PP_PowerPlant::InitializeHeap(3);                    // Initialize Memory Manager
  39.                                                         // Parameter is number of Master Pointer
  40.                                                         // blocks to allocate
  41.     
  42.     PP_PowerPlant::UQDGlobals::InitializeToolbox(&qd);    // Initialize standard Toolbox managers
  43.     
  44.     new PP_PowerPlant::LGrowZone(20000);                // Install a GrowZone function to catch
  45.                                                         // low memory situations.
  46.  
  47.     CBasicApp    theApp;                                    // replace this with your App type
  48.     theApp.Run();
  49.     
  50.     return 0;
  51. }
  52.  
  53.  
  54. // ---------------------------------------------------------------------------
  55. //        • CBasicApp
  56. // ---------------------------------------------------------------------------
  57. //    Constructor
  58.  
  59. CBasicApp::CBasicApp()
  60. {
  61.     RegisterClass_(PP_PowerPlant::LWindow);        // You must register each kind of
  62.     RegisterClass_(PP_PowerPlant::LCaption);    // PowerPlant classes that you use
  63.                                                 // in your PPob resource.
  64.     RegisterClass_(PP_PowerPlant::LPane);        
  65.     RegisterClass_(PP_PowerPlant::LView);        
  66.     RegisterClass_(PP_PowerPlant::LPicture);    
  67.     RegisterClass_(PP_PowerPlant::LStdButton);        
  68. }
  69.  
  70.  
  71. // ---------------------------------------------------------------------------
  72. //        • ~CBasicApp
  73. // ---------------------------------------------------------------------------
  74. //    Destructor
  75.  
  76. CBasicApp::~CBasicApp()
  77. {
  78. }
  79.  
  80. // ---------------------------------------------------------------------------
  81. //        • StartUp
  82. // ---------------------------------------------------------------------------
  83. //    This method lets you do something when the application starts up
  84. //    without a document. For example, you could issue your own new command.
  85.  
  86. void
  87. CBasicApp::StartUp()
  88. {
  89.     ObeyCommand(PP_PowerPlant::cmd_New, nil);        // EXAMPLE, create a new window
  90. }
  91.  
  92. // ---------------------------------------------------------------------------
  93. //        • ObeyCommand
  94. // ---------------------------------------------------------------------------
  95. //    This method lets the application respond to commands like Menu commands
  96.  
  97. Boolean
  98. CBasicApp::ObeyCommand(
  99.     PP_PowerPlant::CommandT    inCommand,
  100.     void                    *ioParam)
  101. {
  102.     Boolean        cmdHandled = true;
  103.  
  104.     switch (inCommand) {
  105.     
  106.         // Handle command messages (defined in PP_Messages.h).
  107.         case PP_PowerPlant::cmd_New:
  108.                                         
  109.             PP_PowerPlant::LWindow    *theWindow =
  110.                                     PP_PowerPlant::LWindow::CreateWindow(wind_SampleWindow, this);
  111.             ThrowIfNil_(theWindow);
  112.             
  113.             //    Hookup the Clear Button
  114.             PP_PowerPlant::LStdButton    *button = (PP_PowerPlant::LStdButton*)theWindow->FindPaneByID(Button_Fish);
  115.             ThrowIfNil_(button);
  116.             button->AddListener(this);
  117.  
  118.             // LWindow is not initially visible in PPob resource
  119.             theWindow->Show();
  120.             break;
  121.  
  122.         case MSG_Fish:
  123.             SysBeep(10);
  124.             break;
  125.  
  126.         // Any that you don't handle, such as cmd_About and cmd_Quit,
  127.         // will be passed up to LApplication
  128.         default:
  129.             cmdHandled = PP_PowerPlant::LApplication::ObeyCommand(inCommand, ioParam);
  130.             break;
  131.     }
  132.     
  133.     return cmdHandled;
  134. }
  135.  
  136. // ---------------------------------------------------------------------------
  137. //        • ListenToMessage
  138. // ---------------------------------------------------------------------------
  139.  
  140. void
  141. CBasicApp::ListenToMessage(
  142.     PP_PowerPlant::MessageT        inMessage,
  143.     void*                        /* ioParam */)
  144. {
  145.     switch (inMessage)
  146.     {
  147.         case MSG_Fish:
  148.         {
  149.             SysBeep(10);
  150.             break;
  151.         }
  152.         
  153.         default:
  154.             break;
  155.     }
  156. }
  157.  
  158. // ---------------------------------------------------------------------------
  159. //        • FindCommandStatus
  160. // ---------------------------------------------------------------------------
  161. //    This method enables menu items.
  162.  
  163. void
  164. CBasicApp::FindCommandStatus(
  165.     PP_PowerPlant::CommandT    inCommand,
  166.     Boolean                    &outEnabled,
  167.     Boolean                    &outUsesMark,
  168.     PP_PowerPlant::Char16    &outMark,
  169.     Str255                    outName)
  170. {
  171.  
  172.     switch (inCommand) {
  173.     
  174.         // Return menu item status according to command messages.
  175.         case PP_PowerPlant::cmd_New:
  176.         case MSG_Fish:
  177.             outEnabled = true;
  178.             break;
  179.  
  180.         // Any that you don't handle, such as cmd_About and cmd_Quit,
  181.         // will be passed up to LApplication
  182.         default:
  183.             LApplication::FindCommandStatus(inCommand, outEnabled,
  184.                                                 outUsesMark, outMark, outName);
  185.             break;
  186.     }
  187. }
  188.